package com.hntx.joymusic.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hntx.joymusic.R;


public class SelectTimeView extends LinearLayout {
    private String TAG = "IpEdit";
    private ImageView image_down;
    private ImageView image_focus;
    private ImageView image_up;
    private int inputNum = -1;
    private LinearLayout mContentView;
    private Context mContext;
    OnFocusChangeListener mOnFocusChangeListener = new OnFocusChangeListener() {
        public void onFocusChange(View view, boolean isFocus) {
            if (isFocus) {
                image_up.setVisibility(View.VISIBLE);
                image_down.setVisibility(View.VISIBLE);
                return;
            }
            image_up.setVisibility(View.INVISIBLE);
            image_down.setVisibility(View.INVISIBLE);
        }
    };
    private TextView mSelectView;
    private String number;

    public SelectTimeView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mContext = context;
        initView();
    }

    private void initView() {
        mContentView = ((LinearLayout) inflate(mContext, R.layout.select_time_view, null));
        mContentView.setDuplicateParentStateEnabled(true);
        addView(mContentView);
        mSelectView = mContentView.findViewById(R.id.item0);
        image_up = mContentView.findViewById(R.id.image_up);
        image_down = mContentView.findViewById(R.id.image_down);
        mSelectView.setOnFocusChangeListener(mOnFocusChangeListener);
        mSelectView.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View view, int keycode, KeyEvent keyEvent) {
                String str1 = TAG;
                StringBuilder localStringBuilder1 = new StringBuilder();
                localStringBuilder1.append(" keyCode = ");
                localStringBuilder1.append(keycode);
                Log.i(str1, localStringBuilder1.toString());
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    if ((keycode >= KeyEvent.KEYCODE_0) && (keycode <= KeyEvent.KEYCODE_9)) {
                        numKeyDown(keycode - 7);
                        mSelectView.setText(number);
                    }
                    if ((keycode == KeyEvent.KEYCODE_DPAD_UP) && (keyEvent.getAction() == KeyEvent.ACTION_DOWN)) {
                        int j = Integer.parseInt(mSelectView.getText().toString());
                        if (j == 9)
                            j = -1;
                        String str3 = TAG;
                        StringBuilder localStringBuilder4 = new StringBuilder();
                        localStringBuilder4.append("currenNum_Up = ");
                        localStringBuilder4.append(j);
                        localStringBuilder4.append("");
                        Log.i(str3, localStringBuilder4.toString());
                        TextView localTextView2 = mSelectView;
                        StringBuilder localStringBuilder5 = new StringBuilder();
                        localStringBuilder5.append(j + 1);
                        localStringBuilder5.append("");
                        localTextView2.setText(localStringBuilder5.toString());
                        return true;
                    }
                    if ((keycode == KeyEvent.KEYCODE_DPAD_DOWN) && (keyEvent.getAction() == KeyEvent.ACTION_DOWN)) {
                        int i = Integer.parseInt(mSelectView.getText().toString());
                        if (i == 0)
                            i = 10;
                        String str2 = TAG;
                        StringBuilder localStringBuilder2 = new StringBuilder();
                        localStringBuilder2.append("currenNum_Down = ");
                        localStringBuilder2.append(i);
                        localStringBuilder2.append("");
                        Log.i(str2, localStringBuilder2.toString());
                        TextView localTextView1 = mSelectView;
                        StringBuilder localStringBuilder3 = new StringBuilder();
                        localStringBuilder3.append(i - 1);
                        localStringBuilder3.append("");
                        localTextView1.setText(localStringBuilder3.toString());
                        return true;
                    }
                }
                return false;
            }
        });
    }

    public String getText() {
        return mSelectView.getText().toString();
    }

    public void numKeyDown(int num) {
        inputNum = num;
        number = String.valueOf(inputNum);
    }

    public void setText(String content) {
        this.mSelectView.setText(content);
    }

    public void setTextColor(int color) {
        this.mSelectView.setTextColor(color);
    }
}